﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Visa.DB;
using Visa.Service;

namespace Visa.Common.MvcContronller
{
   public class UTContext
    {
        public static readonly string SessionContextKey = "SessionForVisa";
        private UserService service = new UserService();
        private RolesSer Rs = new RolesSer();

        private User users = null;

        public User User
        {
            get
            {
                if (!HttpContext.Current.Request.IsAuthenticated)
                {
                    return null;
                }

                if (users == null)
                {
                    string userName = HttpContext.Current.User.Identity.Name;
                    if (!string.IsNullOrEmpty(userName) && users == null)
                    {
                        users = service.GetUserByEmilAndUsName(true, userName);
                    }
                }
                return users;
            }
            private set { users = value; }
        }

        public bool checkUser(string roles)
        {
            return Rs.checkUserIRoles( User.UsID, roles);
        }

        public void LogOut()
        {
            User = null;
        }
    }
}
